#!/bin/bash
#printenv
#echo $PATH | grep -o /usr/bin
#source /home/rfrances/.bashrc
#ls 
tar -zxf PDFs.tar.gz
#ls
#ls -l Pdfdata
#cp -v input.DAT.base input.DAT
#cat input.DAT
inputfile="$3"
echo $inputfile
baserunname=`cat $inputfile | grep runstring | cut -f2 -d"'"`
seed=`genrand.sh 4 1`
runname="$baserunname""_""$1""_""$2"_$seed
echo $runname
# syntax: set_mcfm_parameter.sh ptjet_min 0d0 --file=$basefile -v
set_mcfm_parameter.sh ij $seed --file="$inputfile" -v
set_mcfm_parameter.sh name \'$runname\' --file="$inputfile" -v
if [ "$2" -eq 0  ]; then
 mail -s "MCFM start on: $inputfile on `uname -n` $1 --- "$runname" `date '+%y/%m/%d %H:%M:%S %s'`" rfrances@umd.edu < "$inputfile"
 echo $1 "$runname" `date '+%y/%m/%d %H:%M:%S %s'` >> ~/started_mcfm
fi
lastrun=$(( $4 - 1 )) 
#################################
./mcfm "$inputfile"
#################################
gnuplot *$runname.gnu
loopydo.sh "ls *$runname.ps" ps2pdf
if [ "$2" -eq "$lastrun"  ]; then
 mutt -s "MCFM end: $inputfile" rfrances@umd.edu < "$inputfile"
fi
